using System;
using Spring.Context;
using Spring.Context.Support;

namespace AUSRIS.Reports.Extensions.Security
{
	internal sealed class ProviderFactory
	{
		public static T GetProvider<T>()
			where T : class
		{
			IApplicationContext applicationContext = ContextRegistry.GetContext();
			string key = typeof(T).Name;
			T provider = applicationContext.GetObject(key) as T;
			if ( provider == null )
			{
				throw new Exception(String.Format("No {0} configured", key));
			}
			return provider;
		}
	}
}
